/*
	Get about information. Show serect login page
*/
var aboutVM = function () {

	// Variables for About page
	var datacontext = new DataContext(),
	aboutTitle = ko.observable(getLocalizeText('about')),
	entity = ko.observable(),
	title = ko.observable(),
	description = ko.observable(),
	passWordSecrect = 'get1abstract2',

	// Get about: title, description
	getAbout = function () {
		var list = ko.observableArray([]);
		
		showLoadingDialog();
		isLoading = true;
		datacontext.about.getAbout({
			results: list,
			key: "saveFileabout" + systemLanguage,
            callbackFunc: function(){
                stopLoading();
                if (list().length > 0){
                    var aboutEntity = list()[0].object;
                    title(aboutEntity.title());
                    description(aboutEntity.description());
                    if (myScroll != null) {
                        myScroll.refresh();
                    }
                }
            }
		}).done(function () {
                if (list().length > 0){
                    CheckExpireSession(
                        list,
                        true,
                        function() {
                            getAbout();
                        },
                        function(aboutEntity) {
                            title(aboutEntity.title());
                            description(aboutEntity.description());
                            if (myScroll != null) {
                                myScroll.refresh();
                            }
                        });
                }
			
		}).fail(function (e) {
			/* failed cause internet */
                CheckExpireSessionErrorCallback(e,
                                                function(){
                                                    /* session expired */
                                                    getAbout();
                                                },
                                                function(){
                                                    /* not expire */
                                                });
		});
	},

	reloadLanguage = function () {
		aboutTitle(getLocalizeText('about'));
	},

	// Change domain key and restart application
	changeDomain = function () {
		if (document.getElementById('password_secrect_id').value == passWordSecrect) {
			/* correct password do action */
			if (document.getElementById('domain_name_id').value != undefined && document.getElementById('domain_name_id').value.length > 0) {
				/* clear cache */
                var strNewDomain = 'http://' + document.getElementById('domain_name_id').value + '/';
				model.settingsVM.clearAllData();
				/* save domain name here */
				localStore.save(strDomainKey, strNewDomain);
				alert('Please re-login application to use new domain: ' + localStore.get(strDomainKey));
			} else {
				alert('Please enter domain name');
			}
		} else {
			alert('Wrong password!');
		}
	},

	// Show serect view
	rightClick = function () {
		model.viewSecrectPage();
	};
	
	return {
		aboutTitle: aboutTitle,
		changeDomain: changeDomain,
		title: title,
		entity: entity,
		getAbout: getAbout,
		rightClick: rightClick,
		description: description,
		reloadLanguage: reloadLanguage
	};
}()
